package com.example.test.Admin_function;

import androidx.annotation.RequiresApi;
import androidx.appcompat.app.AppCompatActivity;

import android.app.AlertDialog;
import android.app.TimePickerDialog;
import android.content.DialogInterface;
import android.os.Build;
import android.os.Bundle;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.WindowManager;
import android.widget.Button;
import android.widget.TextView;
import android.widget.TimePicker;
import android.widget.Toast;

import com.example.test.R;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Calendar;
import java.util.List;

public class add_time extends AppCompatActivity implements View.OnClickListener{
    public TimePicker timePicker;
    public Button bt;
    public TimePickerDialog timePickerDialog;
    public Calendar calendar;
    public TextView text_time;
    public int minutes,hours;
    @Override
    protected void onCreate(Bundle savedInstanceState) {

        super.onCreate(savedInstanceState);
        setContentView(R.layout.time);
        timePicker = (TimePicker) findViewById(R.id.begin_time);
        timePicker.setIs24HourView(true);
        bt = (Button) findViewById(R.id.add_time);
        text_time = (TextView) findViewById(R.id.test_time);
        calendar = Calendar.getInstance();
        bt.setOnClickListener(this);

    }

    public void showDailog(){
        timePickerDialog = new TimePickerDialog(this, AlertDialog.THEME_HOLO_DARK, new TimePickerDialog.OnTimeSetListener() {
            @Override
            public void onTimeSet(TimePicker view, int hourOfDay, int minute) {
                Log.d("测试", Integer.toString(hourOfDay));
                Log.d("测试", Integer.toString(minute));
                hours = hourOfDay;
                minutes = minute;
                System.out.println(hours);
                Toast.makeText(add_time.this,"测试时间是:"+hours+"小时"+minute+"分钟",Toast.LENGTH_SHORT).show();
            }
        },
                0,
                0,
                true);
        timePickerDialog.show();
        timePickerDialog.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN);
    }

    public void al(){
        View view = LayoutInflater.from(this).inflate(R.layout.time,null);
        AlertDialog.Builder builder = new AlertDialog.Builder(this);
        builder.setTitle("选择时间");
        builder.setView(view);
        builder.setPositiveButton("确定", new DialogInterface.OnClickListener() {
            @RequiresApi(api = Build.VERSION_CODES.M)
            @Override
            public void onClick(DialogInterface dialog, int which) {
                hours = timePicker.getHour();
//                System.out.println(hours);
//                ss = new ArrayList<>();
//                ss.add(hours);
                Toast.makeText(add_time.this,"shijianshi:"+hours,Toast.LENGTH_SHORT).show();
            }
        });
        builder.setNegativeButton("取消",null);
        AlertDialog dialog = builder.create();
        dialog.show();
        dialog.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN);
    }

    @Override
    public void onClick(View v) {
       showDailog();
    }
}